using System;
using System.Collections.Generic;
using System.Text;
using Adoor.Metadata;
using System.Xml;
using System.IO;

namespace Adoor.Wizard
{
    public class MultiFileDiskWriterProvider : IXmlWriterProvider
    {
        private string basePath;
        private string defaultName;
        public MultiFileDiskWriterProvider(string basePath, string defaultName)
        {
            this.files = new List<string>();
            this.basePath = basePath;
            this.defaultName = defaultName;
        }

        private List<string> files;

        public List<string> Files
        {
            get { return files; }
        }


        #region IXmlWriterProvider Members

        public System.Xml.XmlWriter GetWriter(string name)
        {
            string path;
            if(name == null)
                path = Path.Combine(basePath, defaultName);
            else
                path = Path.Combine(basePath, name);

            string folder = Path.GetDirectoryName(path);
            Directory.CreateDirectory(folder);

            XmlTextWriter xw = new XmlTextWriter(
                path
                , Encoding.Unicode);

            files.Add(path);
            return xw;
        }

        #endregion
    }
}
